<script>
import {Button, Divider} from 'ant-design-vue';

export default {
  name: 'FormulaActions',
  render(h) {
    return h('div', {class: 'h-flow-formula-action'}, this.renderActions(h));
  },
  data() {
    return {
      actions: [
        {type: 'button', name: '+', value: '+'},
        {type: 'button', name: '-', value: '-'},
        {type: 'button', name: '*', value: '*'},
        {type: 'button', name: '/', value: '/'},
        {type: 'button', name: '(', value: '('},
        {type: 'button', name: ')', value: ')'},
        {type: 'divider'},
        {type: 'button', name: '==', value: '=='},
        {type: 'button', name: '!=', value: '!='},
        {type: 'button', name: '>=', value: '>='},
        {type: 'button', name: '<=', value: '<='},
        {type: 'button', name: '<', value: '<'},
        {type: 'button', name: '>', value: '>'},
        {type: 'divider'},
        {type: 'button', name: '并且', value: '&&'},
        {type: 'button', name: '或者', value: '||'},
        {type: 'button', name: '取反', value: '!'},

        {type: 'divider'},
        {type: 'button', name: '明细任意一行', value: ' exist("") '},
        {type: 'button', name: '明细任意一行等于', value: ' anyEqual(列表名,字段名,取值) '},
        {type: 'button', name: '明细所有行等于', value: ' everyEqual(列表名,字段名,取值) '},
        {type: 'button', name: '是否重复', value: ' duplicate(字段名) '},
        {type: 'extend', name: '扩展取值', value: ''},

        {type: 'divider'},
        {type: 'button', name: '取星期几', value: ' getWeek(变量) '},
        {type: 'button', name: '取星期几(数字)', value: ' getWeekNumber(变量) '},
        {type: 'button', name: '取日期', value: ' getDate(变量) '},
        {type: 'button', name: '取时间', value: ' getTime(变量) '},
        {type: 'button', name: '是否为空', value: ' isEmpty(变量) '},
        {type: 'button', name: '日期差', value: ' differDate(字段, 取值) '},
        {type: 'button', name: '取年', value: ' getYear(字段) '},
        {type: 'button', name: '取月', value: ' getMonth(字段) '},
        {type: 'button', name: '取日', value: ' getDay(字段) '},
        {type: 'button', name: '工作年限  ', value: ' yearOfWork(变量) '},
        {type: 'button', name: '明细列合并(文本)', value: 'stringJoin(变量, ",") '},
      ]
    };
  },
  methods: {
    renderActions(h) {
      return this.actions.map(action => this.renderAction(h, action));
    },
    renderAction(h, action) {
      return this[`${action.type}Render`](h, action);
    },
    dividerRender(h, action) {
      return h(Divider, {class: 'h-flow-action-divider'});
    },
    clickButton(action) {
      this.$emit('addAction', action);
    },
    extendRender(h, action) {
      let that = this

      return h(Button, {
        on: {
          click: () => {
            that.$emit('extend');
          }
        }
      }, ['扩展']);
    },
    buttonRender(h, action) {
      return h(Button, {
        class: 'h-flow-action-button',
        on: {
          click: () => this.clickButton(action)
        }
      }, [action.name]);
    },
  }
};
</script>
<style>
.h-flow-formula-action {
  padding: 15px 0 0 15px;
}

.h-flow-action-button {
  margin-right: 15px;
  margin-bottom: 10px;
}

.h-flow-formula-action .h-flow-action-divider {
  margin: 5px 0 15px 0;
}
</style>